<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="胡爱静">
    <title></title>
    <style>
        .box {
            width: 520px;
            height: 280px;
            margin: 100px auto;
        }

        ul {
            margin: 0;
            padding: 0;
            list-style: none;
            position: relative;
        }

        li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }

        li.current {
            display: block;
        }
        .one{
            width: 200px;
            height: 20px;
            background-color: #666;
            border: 1px solid white;
            border-radius: 15px;
            position: relative;
            top: 255px;
            margin: 0 auto;
            display: flex;
            justify-content: space-around;
            opacity: 0.5;
        }
        .one span{
            margin-top: 2px; 
            width: 15px;
            height: 15px;
            background-color: white;
            border-radius: 100%;
        }
        .one .active{
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li class="current"><a href="#"><img src="01.jpg" alt=""></a></li>
            <li><a href="#"><img src="02.jpg" alt=""></a></li>
            <li><a href="#"><img src="03.jpg" alt=""></a></li>
            <li><a href="#"><img src="04.jpg" alt=""></a></li>
            <li><a href="#"><img src="05.jpg" alt=""></a></li>
            
        </ul>
        <div class="one">
                <span class="active"></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
            </div>
    </div>
</body>

</html>
<script>
    var lis = document.querySelectorAll('li');
    var spans = document.querySelectorAll('span');

    //初始 显示索引值为0的第一张
    var index = 0; //记录当前显示图片的索引值
    // 每隔1秒切换一张图片
    var timer = setInterval(changeImage, 1000);
    function changeImage() {
        //先让所有的图片隐藏，去除类名
        for (var i = 0; i < lis.length; i++) {
            lis[i].className = '';
        }
        for (var j = 0; j < spans.length; j++) {
            spans[j].className = '';
        }
        index++;
        if (index == 5) {
            //    当循环到最后一张时再从第一张开始
            index = 0;
        }
        //    根据索引值显示图片
        lis[index].className = 'current';
        spans[index].className = 'active';
    }
    lis[index].onmouseover = function(){
        clearInterval(timer);
        
    }
    lis[index].onmouseout = function(){
        setInterval(changeImage, 1000);
    }


</script>